//
//  LLWelcomeViewControllers.swift
//  xinlangweibo
//
//  Created by 任玉林 on 16/6/26.
//  Copyright © 2016年 任玉林. All rights reserved.
//

import UIKit

import SDWebImage

class LLWelcomeViewControllers: UIViewController {
    
    override func loadView() {
        
        view = bg
    
    }
 
    override func viewDidAppear(animated: Bool) {
        
        super.viewDidAppear(animated)
        
        self.headImageView.snp_updateConstraints { (make) -> Void in
            
            make.top.equalTo(self.view).offset(100)
        }
        
        //动画
        UIView.animateWithDuration(3, delay: 1, usingSpringWithDamping: 0.6, initialSpringVelocity: 0, options: [], animations: { () -> Void in
            
            self.view.layoutIfNeeded()
            
            }) { (_) -> Void in
                
                UIView.animateWithDuration(0.25, animations: { () -> Void in
                    
                    self.messageLabel.alpha = 1
                    
                    }, completion: { (_) -> Void in
                        
                        //动画结束跳到首页控制器
                        NSNotificationCenter.defaultCenter().postNotificationName(SwitchRootVcNoti, object: "welcome")
                        
                        
                })
        }
    }
    
    override func viewDidLoad() {
        
        super.viewDidLoad()
        
        setupUI()
    }
    
    //设置视图
   private func setupUI(){
        
        view.addSubview(headImageView)
        view.addSubview(messageLabel)
        
        //设置约束
        
        headImageView.snp_makeConstraints { (make) -> Void in
            
            make.size.equalTo(CGSize(width: 90, height: 90))
            
            make.top.equalTo(view).offset(400)
            
            make.centerX.equalTo(view)
        }
        
        messageLabel.snp_makeConstraints { (make) -> Void in
            
            make.top.equalTo(headImageView.snp_bottom).offset(16)
            
            make.centerX.equalTo(headImageView)
            
        }
        
    }
    
    //懒加载控件
    
    //背景图片
    private lazy var bg:UIImageView = UIImageView(imageName: "ad_background-1")

    //头像
    private lazy var headImageView: UIImageView = {
        
       let imgView = UIImageView(imageName: "avatar_default_big")
        
        imgView.layer.cornerRadius = 45
        
        imgView.layer.masksToBounds = true
        
        imgView.layer.borderColor = ThemeColor.CGColor
        
        imgView.layer.borderWidth = 3
        
        imgView.sd_setImageWithURL(NSURL(string: LLUserAccountTools.sharedTools.userAccount?.avatar_large ?? ""),placeholderImage:UIImage(named: "avatar_default_big"))

        return imgView
        
    }()

    //欢迎回来文字
    private lazy var messageLabel: UILabel = {
       
        let lab = UILabel()
        
        lab.text = "欢迎回来"
        
        lab.font = UIFont.systemFontOfSize(20)
        
        lab.textAlignment = .Center
        
        lab.textColor = UIColor.grayColor()
        
        lab.alpha = 0
    
        return lab
    }()
}
